package com.xiweicheng.test.proxy.resp.handler;

import java.io.IOException;
import java.net.HttpURLConnection;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DomainRespHandler extends RespHandler {

	@Override
	protected void handle(HttpURLConnection conn, HttpServletResponse resp) throws IOException {

		String content = IOUtils.toString(conn.getInputStream(), "UTF-8");
		
		log.debug("Content[domain.js]: {}", content);

//		content = StringUtils.replace(content, "document.domain='pingan.com.cn';", "document.domain='localhost';");
		content = StringUtils.replace(content, "document.domain='pingan.com.cn';", "");

		IOUtils.write(content, resp.getOutputStream(), "UTF-8");
	}

}
